import store from '@/store'
import app from '../../assets/js/app/index.js'
const firstPage = require('./firstPage.json')
const secondPage = require('./secondPage.json')
let cashData = []
let fileConnection = false
const handleData = path => {
  cashData = [firstPage, secondPage]
  let dataSet = cashData.find(item => item.path == path)
  store.commit('setDataSet', dataSet)
  fileConnection = true
  app.$emit('dataReady')
}
const init = (path = '/') => {
  if (fileConnection) {
    let dataSet = cashData.find(item => item.path == path)
    store.commit('setDataSet', dataSet)
  } else {
    handleData(path)
  }
  app.log('file init')
}
const destroy = () => {
  fileConnection = false
  cashData = []
  app.log('file destroy')
}
export { init, destroy }
